<?php
function set_global_cookie(){
	if(get_cookie('username') == false)//if cookie not exists go to log-in/register page
	{
		$cookie_data['user_sign_in'] = false;
	}else
	{
		$cookie_data['user_sign_in'] = true;
		$cookie_data['username']     = get_cookie('username');
		$cookie_data['realname']     = get_cookie('realname');
	}
	return $cookie_data;
	
}


function make_output($s,$main = array()){

	$cookie_data = set_global_cookie();
	
	$head    = 	$s->smarty->view('head.tpl',null,true);
	$nav     = 	$s->smarty->view('nav_bar.tpl',$cookie_data,true);
	$header  = 	$s->smarty->view('header.tpl',null,true);
	$footer  = 	$s->smarty->view('footer.tpl',null,true);

	$output = $head . $nav . $header . $main . $footer;
	return $output;
}

function get_profile_photo($id=''){
	$r = rand(-2,2);
	if($r>0){
		return "/assets/img/male.jpg";
	}else{
		return "/assets/img/female.jpg";
	}
}
function get_profile_photo_by_id($r){
	if($r==1){
		return "/assets/img/male.jpg";
	}else{
		return "/assets/img/female.jpg";
	}
}
/** 
 * 
 * get the photo takeh time...
 * @param filename
 * @return timestamp if suc else 0;
 */
function get_takentime($filename){
	$exif = exif_read_data(UPLOAD_PATH.$filename, 0, true);
	if(isset($exif['FILE']['FileDateTime'])){
		return $exif['FILE']['FileDateTime'];
	}
	return 0;
}


function get_location_from_google($location_name){
	$lat = rand(-180,180);
	$long = rand(-180,180);
	return array('location'=>$location_name,'lat'=>$lat,'long'=>$long);
}

function get_location_from_lat_long($lat,$long){
	if($lat ==0 && $long ==0){
		return array('location'=>'unknown','lat'=>0,'long'=>0);
	}
	$location_name = readable_random_string(intval(rand(6,13)));
	return array('location'=>$location_name,'lat'=>$lat,'long'=>$long);
}

function readable_random_string($length = 6){
	$conso=array("b","c","d","f","g","h","j","k","l",
    "m","n","p","r","s","t","v","w","x","y","z");
	$vocal=array("a","e","i","o","u");
	$password="";
	srand ((double)microtime()*1000000);
	$max = $length/2;
	for($i=1; $i<=$max; $i++)
	{
	$password.=$conso[rand(0,19)];
	$password.=$vocal[rand(0,4)];
	}
	return $password;
}